﻿using System.Collections.Generic;

namespace Jinndev.Localization {

    public class DefaultLocalizableStorage : ILocalizableStorage {

        private Dictionary<string, string> textData = new Dictionary<string, string>();

        public void Clear() {
            textData.Clear();
        }

        public string Get(string key, bool returnKeyIfNotFound) {
            if (textData.TryGetValue(key, out string text)) {
                return text;
            }
            return returnKeyIfNotFound ? key : null;
        }

        public void Set(string key, string text) {
            if (text == null) {
                textData.Remove(key);
            }
            else if (!textData.ContainsKey(key)) {
                textData.Add(key, text);
            }
        }

    }

}
